testsuite: Add some checks for focus states
authorMatthias Clasen <mclasen@redhat.com>
Thu, 16 Apr 2020 16:09:54 +0000 (12:09 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 16 Apr 2020 16:31:17 +0000 (12:31 -0400)
This is some opportunistic checking in a test that
is really about focus chains, but better than nothing.

testsuite/gtk/test-focus-chain.c

index 53fab0d5a3c7372bd4bfc89042aee0c3031a0126..5419dbc2aef93a82db8fca39a0625a8a8f9c5731 100644 (file)
@@ -86,6 +86,34 @@ done:
   return diff;
 }
 
+static void
+check_focus_states (GtkWidget *focus_widget)
+{
+  GtkStateFlags state;
+  GtkWidget *parent;
+
+  if (focus_widget == NULL)
+    return;
+
+  /* Check that we set :focus and :focus-within on the focus_widget,
+   * and :focus-within on its ancestors
+   */
+
+  state = gtk_widget_get_state_flags (focus_widget);
+  g_assert_true ((state & (GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN)) ==
+                  (GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN));
+
+  parent = gtk_widget_get_parent (focus_widget);
+  while (parent)
+    {
+      state = gtk_widget_get_state_flags (parent);
+      g_assert_true ((state & GTK_STATE_FLAG_FOCUS_WITHIN) == GTK_STATE_FLAG_FOCUS_WITHIN);
+      g_assert_true ((state & GTK_STATE_FLAG_FOCUSED) == 0);
+
+      parent = gtk_widget_get_parent (parent);
+    }
+}
+
 static char *
 generate_focus_chain (GtkWidget        *window,
                       GtkDirectionType  dir)
@@ -109,6 +137,8 @@ generate_focus_chain (GtkWidget        *window,
 
       focus = gtk_window_get_focus (GTK_WINDOW (window));
 
+      check_focus_states (focus);
+
       if (focus)
         {
           /* ui files can't put a name on the embedded text,